#include <stdio.h>
#include "bruch.h"
/*
 * helper.c
 *
 *  Created on: 16.08.2011
 *      Author: stephan
 */
/*DEPRECTED. Old Monster function with minimal output,

int ggt_old(int a, int b) {
	int i;
	if (a > b) {
		i = b;
	} else {
		i = a;
	}
	while (i > 0) {
		if ((a % i) == 0) {
			if ((b % i) == 0) {
				return i;
			}
		}
		i--;
	}
	return 0;
}

 TASK. Better solution with Euclid, without temp variable and with recursion
*/
int ggt(int a, int b) {
        if((a%b)==0){
                return b;
        }
        else{
                ggt(b,(a%b));
        }
}


int kgv(int a, int b) {
	int kl;
	int gr;
	int z=1;
	if (a > b) {
		kl = b;
		gr = a;
	} else {
		kl = a;
		gr = b;
	}

	while(z < (gr*kl)) {
		if ((kl*z) % gr == 0) {
			return (kl * z);
		}
		z++;

	}
	return 0;
}

void kuerze(Ratio *x){
	int z=ggt(x->zaehler, x->nenner);
	(*x).zaehler=(*x).zaehler/z;
	(*x).nenner=(*x).nenner/z;
}

Ratio weiter(Ratio x, int i){
	Ratio tmp;
	tmp.zaehler=x.zaehler*i;
	tmp.nenner=x.nenner*i;
	return tmp;
}


